import subprocess
import sys
import os
import json
import argparse
import requests
import warnings
import shlex
import re

def install_dependency():
    # 安装tox工具
    try:
        cmd = "sudo apt-get install -y tox"
        subprocess.run(
            shlex.split(cmd),
            check=True,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE
        )
        print("✅ tox 安装成功")
    except subprocess.CalledProcessError as e:
        print(f"❌ 安装失败: {e.stderr}")
        sys.exit(1)
    except FileNotFoundError:
        print("❌ 找不到apt-get命令，请确保在Debian/Ubuntu系统上运行")
        sys.exit(1)

    # 安装requirements里面的依赖项
    try:
        subprocess.run(
            ["pip", "install", "-r", "requirements.txt"],
            check=True,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
            text=True,
        )
        print("✅ 依赖安装成功！")
    except subprocess.CalledProcessError as e:
        print(f"❌ 依赖安装失败！错误信息：\n{e.stderr}")
        sys.exit(1)

if __name__ == "__main__":
    install_dependency()
